import pytest
from selenium import webdriver
from Page.Page import Page
from Page.Page1 import Page1
from Page.Page2 import Page2
import time,logging
from selenium.webdriver.common.by import By
from Tools.get_log import send_log

class TestCase():
    @pytest.fixture(scope='function')
    def driver(self):
        driver = webdriver.Edge()
        driver.maximize_window()
        # 日志调用
        send_log()
        yield driver
        driver.quit()

    # 业务1：删除收货地址
    def test_jiuxian_01(self,driver):
        p = Page1(driver)
        # 日志采集
        logging.info('-----start-----')
        p.open_url('https://jiuxian.com/')
        p.pleace_login()
        userlogin = driver.find_element(By.XPATH,'//*[@id="loginform"]/div/div/div/div/div[1]/div[1]/a[1]').text
        print(userlogin)
        assert '帐号登录',userlogin
        p.username()
        p.password()
        # 强等输入验证码
        time.sleep(10)
        p.login_btn()
        p.sure()
        aa = (By.XPATH, '/html/body/div[2]/div/div[1]/div/p/span')
        user_name = p.find_element(aa).text
        print(user_name)
        assert 'jxw385236693' == user_name

        p.wode()
        p.new_window()
        p.scroll_To(800)
        p.address_btn()
        p.delete_address()
        p.sure_delete()
        bb=(By.XPATH,'/html/body/div[8]/div/div[2]/p/span')
        deletesuccess = p.find_element(bb).text
        print(deletesuccess)
        assert '删除成功！',deletesuccess
        p.sure_zai()
        # 日志采集
        logging.info('-----end-----')

    # 业务2：添加商品到购物车
    def test_jiuxian_02(self,driver):
        p = Page2(driver)
        # 日志采集
        logging.info('-----start-----')
        p.open_url('https://jiuxian.com/')
        p.pleace_login()
        userlogin = driver.find_element(By.XPATH, '//*[@id="loginform"]/div/div/div/div/div[1]/div[1]/a[1]').text
        print(userlogin)
        assert '帐号登录', userlogin
        p.username()
        p.password()
        # 强等输入验证码
        time.sleep(10)
        p.login_btn()
        p.sure()
        aa = (By.XPATH, '/html/body/div[2]/div/div[1]/div/p/span')
        user_name = p.find_element(aa).text
        print(user_name)
        assert 'jxw385236693' == user_name

        p.search()
        p.search_btn()
        p.choice_sp()
        p.new_window()
        p.add_card()
        aa = (By.XPATH,'//*[@id="u-buy-layId"]/div/div[2]/span')
        add_success = p.find_element(aa).text
        print(add_success)
        assert '已成功加入购物车',add_success
        # 日志采集
        logging.info('-----end-----')

